//
//  JInNavgationController.swift
//  微博项目
//
//  Created by admin on 16/3/3.
//  Copyright © 2016年 jin. All rights reserved.
//

import UIKit

class JInNavgationController: UINavigationController,UINavigationControllerDelegate {

    override class func initialize()
    {
        var appearance:UIBarButtonItem?
        if #available(iOS 9.0, *) {
            appearance = UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([JInNavgationController.self])
        } else {
            appearance = UIBarButtonItem.my_appearanceWhenContainedIn(JInNavgationController.self)
        }
        appearance?.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Normal)
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        self.delegate = self
        self.interactivePopGestureRecognizerTemp = self.interactivePopGestureRecognizer?.delegate
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        // 子控制器大于0时代表不是跟控制器，隐藏tabbar
        if self.childViewControllers.count > 0
        {
            // 只对系统的tabbar产生作用
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: true)
        
    }
    var interactivePopGestureRecognizerTemp:UIGestureRecognizerDelegate?
    func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {
        if self.viewControllers[0] != viewController
        {
            self.interactivePopGestureRecognizer?.delegate = nil
        }
        else
        {
            self.interactivePopGestureRecognizer?.delegate = self.interactivePopGestureRecognizerTemp
        }
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
